import ResourcesManager from "../../engine/ResourceManager"
import SettingModel from "../model/SettingModel";
import { UserModel } from "../model/UserModel";

export class AudioHelper {

    private static lastMusicClip: cc.AudioClip;

    public static playMusic(clip: cc.AudioClip = null, loop: boolean = true) {
        if (!clip) {
            clip = this.lastMusicClip;
        }
        this.lastMusicClip = clip
        if (clip && SettingModel.instance.musicVolumn == 1) {
            cc.audioEngine.playMusic(clip, loop)
        }
    }
    public static playePathMusic(path: string) {
        ResourcesManager.instance.load(path, () => { }, (clip: cc.AudioClip) => {
            this.playMusic(clip, true)
        })
    }

    public static stopMusic() {
        cc.audioEngine.stopMusic()
    }

    public static stopEffect() {
        cc.audioEngine.stopAllEffects()
    }

    public static playEffect(clip: cc.AudioClip) {
        if (clip && SettingModel.instance.soundVolum == 1) {
            cc.audioEngine.playEffect(clip, false)
        }
    }

    public static playePathEffect(path: string) {
        ResourcesManager.instance.load(path, () => { }, (clip: cc.AudioClip) => {
            this.playEffect(clip)
        })
    }

    public static playBGM() {
        // let path: string = "audio/bgMain"
        // this.playePathMusic(path)
    }

    public static playPress() {
        let path: string = "audio/press"
        this.playePathEffect(path)
    }


}



